package com.reform.mapper;

import com.reform.pojo.common.Dealt;
import com.reform.pojo.project.*;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * VIEW Mapper 接口
 * </p>
 *
 * @author mortale
 * @since 2021-07-21
 */
@Mapper
public interface ViewProjectMapper extends BaseMapper<ViewProject> {
    String getRecentProject(String batch_id, String belong);

    @Select("select pro_id from project WHERE batch_id = #{batchId} AND pro_approval = 1")
    List<String> getProIdByBatchId(@Param("batchId") String batchId);

    /**
     * 根据gh查询该教师主持的项目信息
     * 该操作可以获得批次编号、项目名称、项目编号、项目级别、项目当前状态
     *
     * @param gh 教师工号
     * @return List<MyProjectInfo>
     */
    List<MyProjectInfo> getHostProjectsByGH(@Param("gh") String gh);

    /**
     * 根据gh查询该教师参与的项目信息
     * 该操作可以获得批次编号、项目名称、项目编号、项目级别、项目当前状态
     *
     * @param gh 教师工号
     * @return List<MyProjectInfo>
     */
    List<MyProjectInfo> getPartakeProjectsByGH(@Param("gh") String gh);

    /**
     * 通过项目id获取研究工作简历
     * @param proId 项目id
     * @return List<ProjectSearching>
     */
    List<ProjectSearching> selectSearchingList(@Param("proId") String proId);

    /**
     * 通过项目id获取教学工作信息
     * @param pro_id 项目id
     * @return List<ProjectTeaching>
     */
    List<ProjectTeaching> selectTeachingList(@Param("proId")String pro_id);

    @Select("SELECT\n" +
            "pro_id AS proId,\n" +
            "pro_name AS proName,\n" +
            "pro_department AS proDepartment,\n" +
            "member_name AS memberName,\n" +
            "pro_approval AS proApproval,\n" +
            "member_dep AS memberDep\n" +
            "FROM\n" +
            "view_project\n" +
            "WHERE\n" +
            "pro_approval = ${pro_approval} AND\n" +
            "ranking = 1 AND\n" +
            "batch_id = #{batchId}\n" +
            "GROUP BY\n" +
            "view_project.pro_id")
    List<SimplifyProjectInfo> getSimplifyProjectByBatchId(@Param("batchId")String batch_id,@Param("pro_approval")Integer pro_approval);

    /**
     * 获取延期简单项目信息
     * @param proApproval 项目状态
     * @return List<DelayProject>
     */
    @Select(
            "SELECT\n" +
            "	view_project.batch_id, \n" +
            "	view_project.pro_id AS proId, \n" +
            "	view_project.pro_name AS proName, \n" +
            "	view_project.pro_approval AS proApproval, \n" +
            "	view_project.delay_cause AS delayCause, \n" +
            "	( SELECT phase_time.phase_name FROM phase_time WHERE phase_time.batch_id = view_project.batch_id ) AS batchName, \n" +
            "	(\n" +
            "	SELECT\n" +
            "		phase_time.phase_name \n" +
            "	FROM\n" +
            "		phase_time \n" +
            "	WHERE\n" +
            "		phase_time.type = 3 \n" +
            "		AND phase_time.phase_id IN ((\n" +
            "			SELECT\n" +
            "				batch_phase.phase_id \n" +
            "			FROM\n" +
            "				batch_phase \n" +
            "			WHERE\n" +
            "				batch_phase.batch_id = view_project.batch_id \n" +
            "			)) \n" +
            "	) AS phaseName, \n" +
            "	view_project.pro_department AS proDepartment, \n" +
            "	view_project.pro_dep_id AS proDepId\n" +
            "FROM\n" +
            "	view_project\n" +
            "WHERE\n" +
            "	view_project.pro_approval = ${proApproval}\n" +
            "GROUP BY\n" +
            "	view_project.pro_id"
    )
    List<DelayProject> getAllDelayProject(@Param("proApproval") int proApproval);

    @Select(
            "SELECT\n" +
            "pro_id AS id,\n" +
            "pro_name AS name,\n" +
            "batch_id AS batchId, \n" +
            "fa_level_id AS levelId, \n" +
            "classification AS classification, \n" +
            "classify_name AS classifyName, \n" +
            "(SELECT phase_teacher_end FROM phase_time WHERE phase_time.batch_id = `view_project_member`.batch_id) AS timeEnd\n" +
            "FROM\n" +
            "	`view_project_member` \n" +
            "WHERE\n" +
            "	belong = #{gh} \n" +
            "	AND pro_approval = 5\n" +
            "GROUP BY\n" +
            "pro_id"
    )
    List<Dealt> getTeacherDealt(@Param("gh") String gh);
}
